package com.itheima.leyou.controller;

import com.alibaba.fastjson.JSONObject;
import com.itheima.leyou.service.StockService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
public class StockController {

    @Resource
    private StockService stockService;

    @RequestMapping(value = "/getStockList")
    public Map<String, Object> getStockList(){
        return stockService.getStockList();
    }

    @RequestMapping(value = "/getStock/{sku_id}")
    public Map<String, Object> getStock(@PathVariable("sku_id") String sku_id){
        return stockService.getStock(sku_id);
    }

    @RequestMapping(value = "/insertLimitPolicy/{jsonObj}")
    public Map<String, Object> insertLimitPolicy(@PathVariable("jsonObj") String jsonObj){
        Map<String, Object> map = JSONObject.parseObject(jsonObj, Map.class);
        return stockService.insertLimitPolicy(map);
    }
}
